package com.cnkvha.trackcontestmgmt.ui;

import com.cnkvha.trackcontestmgmt.TrackContestManagement;
import com.cnkvha.trackcontestmgmt.contest.Contest;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class ContestListRenderer extends JPanel implements ListCellRenderer<Contest>  {

    private JPanel indicatorState;
    private JLabel textName;

    public ContestListRenderer() {
        FlowLayout flow = new FlowLayout();
        flow.setHgap(2);
        flow.setVgap(4);
        setLayout(flow);

        indicatorState = new JPanel();
        indicatorState.setPreferredSize(new Dimension(16, 16));
        indicatorState.setMinimumSize(new Dimension(16, 16));
        indicatorState.setMaximumSize(new Dimension(16, 16));
        indicatorState.setBackground(Color.RED);
        add(indicatorState);

        textName = new JLabel("text");
        textName.setFont(new Font("SimHei", 0, 14));
        add(textName);
    }

    private static final Color bg_current = new Color(0x7AB470);

    @Override
    public Component getListCellRendererComponent(JList<? extends Contest> list, Contest value, int index, boolean isSelected, boolean cellHasFocus) {
        if(TrackContestManagement.instance.getCurrentContest() == value) {
            setBackground(bg_current);
        } else {
            if(isSelected) {
                setBackground(Color.CYAN);
            } else {
                setBackground(Color.LIGHT_GRAY);
            }
        }
        Color c = value.state.getIndicatorColor();
        indicatorState.setBackground(c);
        textName.setText(value.name);
        return this;
    }
}
